####################################################################################################
#imports
import os, os.path
import random
import string

import cherrypy

####################################################################################################
#classes
class HelloWorld(object):
    @cherrypy.expose
    def index(self):
        return """<html>
          <head>
            <link href="/static/css/site.css" rel="stylesheet">
          </head>
          <body>
            <form method="get" action="generate">
              <input type="text" value="8" name="length" />
              <button type="submit">Give it now!</button>
            </form>
          </body>
        </html>"""

        
    #@cherrypy.expose
    #def generate(self):
    #    return ''.join(random.sample(string.hexdigits, 8))
        
    @cherrypy.expose
    def generate(self, length=8):
        return ''.join(random.sample(string.hexdigits, int(length)))
        
    @cherrypy.expose
    def display(self):
        return cherrypy.session['mystring']
        
    @cherrypy.expose
    def test(self):
        import jinja2
        #from jinja2 import Environment, PackageLoader
        #env = Environment(loader=PackageLoader('yourapplication', 'templates'))
        
        JINJA_ENVIRONMENT = jinja2.Environment(
            loader=jinja2.FileSystemLoader(os.path.join(os.path.dirname(__file__), 'pages')),
            extensions=['jinja2.ext.autoescape'],
            autoescape=True)
            
        template = JINJA_ENVIRONMENT.get_template('index.html')
        template_values = {}
        template_values['test'] = 'my test string'
        #self.response.write(template.render(self.template_values))

        return template.render(template_values)
        
    @cherrypy.expose
    def test2(self):
        return __file__

    @cherrypy.expose
    def test3(self):
        return __name__ #Tutorial
        
    @cherrypy.expose
    def test4(self):
        return 'asd','zxc', __name__, __file__, '[END]'